package com.wzh.goods.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.wzh.goods.entity.ActivityEntity;
import com.wzh.goods.feign.ActivityFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wzh.goods.entity.GoodsEntity;
import com.wzh.goods.service.GoodsService;
import com.wzh.common.utils.PageUtils;
import com.wzh.common.utils.R;



/**
 * 
 *
 * @author wzh
 * @email 1281204121@qq.com
 * @date 2022-02-22 09:22:46
 */
@RestController
@RequestMapping("goods/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;



    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    public R info(@RequestParam("activityId") Long activityId,@RequestParam("goodsId") Long goodsId){

        return goodsService.getBys(activityId,goodsId);
    }

    /**
     * 查询信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        GoodsEntity goods = goodsService.getById(id);
        return R.ok().put("goods",goods);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsEntity goods){
		goodsService.save(goods);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsEntity goods){
		goodsService.updateById(goods);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		goodsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
